package us.icitap.commandcenter.business;


import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import us.icitap.commandcenter.business.ejb.persistence.Call;
import us.icitap.commandcenter.utils.Utils;
import us.icitap.utils.AppPdf;

import com.itextpdf.text.BaseColor;
import com.itextpdf.text.Chunk;
import com.itextpdf.text.Document;
import com.itextpdf.text.Font;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.draw.LineSeparator;

public class DailyReportPdf extends AppPdf{



	public DailyReportPdf(List<Call> callList, Date[] shiftLimits)  {
		super("SISTEMI", "komunikata-ditore.pdf");
		
		try {
			Document document  = this.getDocument();
			
		
			Paragraph para = new Paragraph("KOMUNIKATA DITORE E TELEFONATAVE");
	        para.setAlignment(1);
	        para.getFont().setStyle(Font.BOLD);
	        para.getFont().setSize(12);
	        document.add(para);
	        
	        para = new Paragraph("Periudha: nga data " + Utils.formatedDateTime(shiftLimits[0]) + " deri ne daten " + Utils.formatedDateTime(shiftLimits[1]) );
	        para.setAlignment(1);
	        para.getFont().setStyle(Font.BOLD);
	        para.getFont().setSize(10);
	        document.add(para);
	        
	        document.add(Chunk.NEWLINE);
	        
    	
	        for (Call call : callList) {
	        	
	        	
	        	
	        	String s = "Sot me date " + Utils.formatedDateTime(call.getRecordDate()) + " telefonoi " + call.getCaller() + ", deklaroi: " + 
	        	call.getDescription() + " ne adresen :" + call.getAddress() + ". ";
	        	CustParagraph p = new CustParagraph(s);
	        	document.add(p);
	        	s = "Telefonata u klasifikua si: " + (call.getCallReason() != null?call.getCallReason().getTag() : "") + ", " + 
	        	(call.getActualGrade()!= null?call.getActualGrade().getTag():"") + " per: " + (call.getMainDispatcher()!= null?call.getMainDispatcher().getName():"") + ". ";
	        	p = new CustParagraph(s);
	        	document.add(p);
	        	s= "U njoftuan : " + call.getNotificationsInfo()+ " dhe u derguan patrullat: " + call.getPatrolsInfo();
	        	p = new CustParagraph(s);
	        	document.add(p);
	        	s= "U derguan patrullat: " + call.getPatrolsInfo();
	        	p = new CustParagraph(s);
	        	document.add(p);
	        	
	        	s= "Telefonata u verifikua ne oren: " + Utils.formatedDateTime(call.getVerificationDate()) + ", e llojit: " + (call.getVerifiedCallReason()!= null?call.getVerifiedCallReason().getTag():"") + ". ";
	        	p = new CustParagraph(s);
	        	document.add(p);
	        	s = "Shenime mbi verifikimin: " + call.getVerifNotesFormatted();
	        	p = new CustParagraph(s);
	        	document.add(p);
	        	s = "Masat e marra: " + call.getPoliceActionListString() + ". ";
	        	p = new CustParagraph(s);
	        	document.add(p);
	        	
	        	document.add(Chunk.NEWLINE);

			}
	        LineSeparator ls = new LineSeparator(1,100 , BaseColor.BLACK, 1, -3);
	        
	        document.add(ls);
	        
	        CustParagraph cp = new CustParagraph("Numri i telefonatave ne kete komunikate eshte: " + callList.size());
	        document.add(cp);
	        document.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
        	
		
	}
	
	
	private class CustParagraph extends Paragraph{
		public CustParagraph(String text) {
			super(text);
			this.getFont().setSize(8);
		}
		
	}
	
}
